package com.codingman.data.mybatis.support;

import java.lang.reflect.Type;
import org.apache.ibatis.builder.annotation.ProviderContext;
import org.springframework.core.ResolvableType;
import com.codingman.data.mybatis.mapper.CrudMapper;

public abstract class BaseSqlProviderSupport {

	protected Class<?> getEntityClass(ProviderContext context) {
		Class<?> mapperType = context.getMapperType();
		for (Type parent : mapperType.getGenericInterfaces()) {
			ResolvableType parentType = ResolvableType.forType(parent);
			if (parentType.getRawClass() == CrudMapper.class) {
				return parentType.getGeneric(0).getRawClass();
			}
		}
		return null;
	}

}
